package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private DtsBrandMapper brandMapper;

    @Override
    public IPage<DtsBrand> findByPage(Integer page, Integer limit, String id, String name, String sort, String order) {
        Page<DtsBrand> iPage = new Page<>(page, limit);
        QueryWrapper<DtsBrand> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name", name);
        }
        if (!StringUtils.isEmpty(id)){
            queryWrapper.like("id", name);
        }
        if ("asc".equalsIgnoreCase(order)){
            queryWrapper.orderByAsc(sort);
        }else {
            queryWrapper.orderByDesc(sort);
        }

        Page<DtsBrand> pageResult = brandMapper.selectPage(iPage, queryWrapper);
        return pageResult;
    }
}
